package it.unibz.easytravel.server.handlers;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import it.unibz.easytravel.server.MessageHandler;
import it.unibz.easytravel.server.util.ZipTools;

public class KmlHandler implements MessageHandler {

	@Override
	public void handle(HttpServletRequest request, HttpServletResponse response) {
		try {
			InputStream content = request.getInputStream();
			InputStream unzippedContent = ZipTools.unzip(content);
			int i;
			while((i = unzippedContent.read()) != -1) {
				System.out.print((char)i);
			}
			response.setContentType("text/plain;charset=UTF-8");
			response.setStatus(HttpServletResponse.SC_OK);
			response.getWriter().println("Yo, yo, gangsters!!"+request.getContentType()+" "+request.getContentLength());
		}
		catch(IOException e) {
			e.printStackTrace();
		}

	}

}
